package demo.wall.controller;

import demo.wall.model.MessageInfo;
import demo.wall.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageInfoController {

    @Autowired
    private MessageInfoService messageInfoService;

    @RequestMapping("/publish")
    public Boolean publish(MessageInfo messageInfo){
        System.out.println(messageInfo);
        if(StringUtils.hasLength(messageInfo.getTo()) &&
        StringUtils.hasLength(messageInfo.getFrom()) &&
        StringUtils.hasLength(messageInfo.getMessage())){
            messageInfoService.addMessage(messageInfo);
            return true;
        }
        return false;
    }

    @RequestMapping("/get")
    public List<MessageInfo> get(){
        return messageInfoService.getAll();
    }
}
